﻿var tb_Text;
var btn_Add;
var btn_AddChild;
var btn_Modify;
var btn_Delete;
var jtv_Categories;

function checkButtonDisplay() {
	var objs = document.getElementsByTagName("input");
	var hasChecked = false;

	for (var i = 0; i < objs.length; i++) {
		if (objs[i].type == 'checkbox') {
			var obj = objs[i];
			if (obj.id.indexOf(jtv_Categories.id) != -1) {
				if (obj.checked) {
					hasChecked = true;
					break;
				}
			}
		}
	}

	if (hasChecked) {
		if (tb_Text.value == "") {
			btn_Add.disabled = true;
			btn_AddChild.disabled = true;
			btn_Modify.disabled = true;
		}
		else {
			btn_Add.disabled = false;
			btn_AddChild.disabled = false;
			btn_Modify.disabled = false;
		}

		btn_Delete.disabled = false;
	}
	else {
		if (tb_Text.value == "") {
			btn_Add.disabled = true;
		}
		else {
			btn_Add.disabled = false;
		}

		btn_AddChild.disabled = true;
		btn_Modify.disabled = true;
		btn_Delete.disabled = true;
	}
}

// Treeview ChekBox节点单选的处理事件
function TreeSingleSelect(treeID, checkNode) {
	if (!treeID) {
		return;
	}

	var objs = document.getElementsByTagName("input");

	for (var i = 0; i < objs.length; i++) {
		if (objs[i].type == 'checkbox') {

			var obj = objs[i];
			if (obj.id.indexOf(treeID) != -1) {

				if (obj != checkNode) {
					obj.checked = false;
				}
			}
		}
	}
}

// 给TreeView的CheBox添加单击事件
function SetTreeNodeClickHander(treeID) {
	var objs = document.getElementsByTagName("input");

	for (var i = 0; i < objs.length; i++) {
		if (objs[i].type == 'checkbox') {

			var obj = objs[i];
			if (obj.id.indexOf(treeID) != -1) {
				objs[i].onclick = function() {
					TreeSingleSelect(treeID, this);
					checkButtonDisplay();
				};
			}
		}
	}
}	